#ifndef CHAT_DATABASE_HPP
#define CHAT_DATABASE_HPP

#include <string>
#include <vector>
#include <reflect_json.hpp>

/*
 * 注册格式 {"msgID","name","password"}                     {"msgID":2,"name":"xts","password":"123456"}
 * 登录格式 {"msgID","name","password","userid"}                {"msgID":1,"name":"xts","password":"123456","id":1}
 * 私聊格式 {"msgID","fromID","fromName","toID","massage"}
 * 正常回应 {"error","msgID","id","name"}
 * 错误回应 {"error","errorMsg","msgID"}
 *
 * */

//请求消息类型
enum ReqType{
    Logic=1,//登录请求
    Register,//注册请求
    OneChat,//点对点聊天请求
    AddFriend,//添加好友请求
    CreatGroup,//创建群
    AddGroup,//添加群
    GroupChat,//群聊天
};

//回应消息类型
enum ResType{
    NoError,//没有错误
    OnlineError,//已在线错误
    NameOrPasswordError,//账号或密码错误
    RegisterError,//注册失败
    LogicAck,//登录响应消息
    RegisterAck,//注册响应消息
};

//数据表所需数据
namespace MySQLTable{
    //user表
    struct User{
        int id = -1;
        std::string name = "";
        std::string password = "";
        std::string state = "offline";
    };
    //offlinemessage表
    struct OfflineMessage{
        int userid = -1;
        std::string message;
    };
    //friend表
    struct Friend{
        int userid = -1;
        int friendid = -1;
    };
    //groupuser表
    struct GroupUser{
        int groupid = -1;
        struct User user;
        std::string role;//在群里的身份
    };
    //allgroup表
    struct AllGroup{
        int id = -1;
        std::string name;
        std::string desc;
        std::vector<GroupUser> users;
    };
}

struct MySQLConfig{
    std::string ip ;
    unsigned int port;
    std::string user;
    std::string pwd;
    std::string dbName;
};

struct PoolConfig {
    MySQLConfig mysqlConfig;//mysql 配置
    int initSize;//连接池初始大小
    int maxSize;//连接池最大连接量
    int maxIdleTime;//连接池 单个连接 最大空闲时间 单位 s
    int connectTimeout;//连接池获取连接的超时时间 单位 ms
};
#endif